package com.esgpro.esg_api.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.esgpro.esg_api.mapper.DataContentMapper;
import com.esgpro.esg_api.pojo.DataContent;
import com.esgpro.esg_api.service.Info.DataContentServiceInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class DataContentServiceImpl implements DataContentServiceInfo {
    @Autowired
    DataContentMapper mapper;

    @Override
    public boolean insertOne(DataContent tag) {
        return mapper.insert(tag) == 1;
    }

    @Override
    public boolean deleteOneById(int id) {
        return mapper.deleteById(id) == 1;
    }

    @Override
    public DataContent selectOneById(int id) {
        return mapper.selectById(id);
    }

    @Override
    public HashMap<String, Object> selectByMap(int current, int size, HashMap<String, Object> map) {
        IPage<DataContent> page = new Page<>(current, size);
        page = mapper.selectPage(page, new QueryWrapper<DataContent>().allEq(map));
        HashMap<String, Object> result = new HashMap<>();
        result.put("total", page.getTotal());
        result.put("list", page.getRecords());
        result.put("current", page.getCurrent());
        result.put("size", page.getSize());
        result.put("page", page.getPages());
        return result;
    }

    @Override
    public boolean updateById(DataContent tag) {
        return mapper.updateById(tag) == 1;
    }

    @Override
    public List<DataContent> selectAll() {
        return mapper.selectList(null);
    }
}
